package org.mct.mes.controller;

import com.github.pagehelper.PageInfo;
import org.mct.mes.entity.MesRawData2;
import org.mct.mes.service.MesRawData2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.security.SecureRandom;
import java.time.Instant;
import java.util.List;

@RestController
@RequestMapping("/MesRawData2")
@CrossOrigin//支持跨域
public class MesRawDataController {
    @Autowired
    MesRawData2Service  mesRawData2Service;

    @GetMapping
    public ResponseEntity<PageInfo<MesRawData2>> testController(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "7") int pageSize,
            @RequestParam(defaultValue = "") String device_code,
            @RequestParam(defaultValue = "")String queryTimeStart,
            @RequestParam(defaultValue = "")String queryTimeEnd){
        System.err.println(pageNum+" "+pageSize+" "+device_code+" "+queryTimeStart+" "+queryTimeEnd);
        Instant startTime = Instant.parse(queryTimeStart);
        Instant endTime = Instant.parse(queryTimeEnd);
        PageInfo<MesRawData2> mesRawData2PageInfo = mesRawData2Service.query10(pageNum,pageSize,device_code,startTime,endTime);
        return ResponseEntity.ok(mesRawData2PageInfo);
    }

    @PostMapping
    public String addMesRawDataOne(@RequestBody MesRawData2 mesRawData2){
        System.out.println(mesRawData2.toString());
        mesRawData2Service.addOne(mesRawData2);
        return "上传了数据";
    }
}
